<?php

require_once 'phpmoko/ui/RootPanel.php';
require_once 'phpmoko/ui/Widget.php';

class Gallery extends Widget
{
	private $list = array();
	
	function __construct()
	{
		parent::__construct();

		$this->id = RootPanel::getUniqueId();

		require_once 'phpmoko/externals/JQueryGalleryPlugin.php';
		JQueryGalleryPlugin::activate();
	}

	function addImage($title, $thumbnail, $image)
	{
		$this->list[] = array($title, $thumbnail, $image);
	}
	
	function toString()
	{
		if (sizeof($this->list) == 0)
			return '';

		if (sizeof($this->list) == 1)
		{
			$lista = $this->list[0];
			return '<img src="'.$lista[2].'" title="'.$lista[0].'">';
		}

		$str = '<div id="'.$this->getId().'" class="gallery">';
		$str .= '<ul class="galleryBar">';
		
		foreach ($this->list as $lista)
			$str .= '<li><a href="'.$lista[2].'"><img src="'.$lista[1].'" title="'.$lista[0].'"></a></li>';
		
		$str .= '</ul>';
		$str .= '</div>';

		$root = RootPanel::get();
		$root->addJSOnReadyDocument('$(\'#'.$this->getId().'\').gallery({showOverlay:true, barPosition: \'top\', ratio: 0.07, height: \'450px\', width: \'600px\'});');
		
		return $str;
	}
}
?>